package com.chisheng.config;

import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.core.injector.SqlRunnerInjector;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.chisheng.mapper")
public class CustomConfiguration {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {

        /* 配置 MybatisPlus 拦截器 v3.4.0+ */

        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        /* 添加 OptimisticLockerInnerInterceptor 拦截器 */
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        /* 添加 PaginationInnerInterceptor 拦截器 */
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }

    @Bean
    public ISqlInjector iqlInjector() {

        /* 配置逻辑删除注入器 v3.0.0+ */

        return new DefaultSqlInjector();
    }

}
